home *** CD-ROM | disk | FTP | other *** search
- // Scene File: CATMULL.PI
- // Author: Rob McGregor
-
- // Uses Catmull-Rom spline interpolation *through*
- // key frame points to calculate an object's path...
-
- include "..\..\..\colors.inc"
- include "..\..\..\texture.inc"
- include "..\..\..\stones.inc"
-
- // Set up the camera
- viewpoint {
- from <0, 0, -12>
- at <0, 0, 0>
- up <0, 1, 0>
- angle 45
- resolution 320,200
- aspect 1.6
- }
-
- // Define the range of the animation
- start_frame 0
- end_frame 49
- outfile "catml"
-
- /********************************************************
- The control points are:
-
- <0, 0, 0>, <1.6, 2.8, 0>, <3.6, 0, 0>,
- <0.4, -3.2, 0>, <-3.2, -0.4, 0>, <0, 0, 0>
-
- The first and last points are doubled to include them
- in the interpolation and create a smoother loop.
-
- x-axis: 0, 0, 1.6, 3.6, 0.4, -3.2, 0, 0
- y-axis: 0, 0, 2.8, 0, -3.2, -0.4, 0, 0
- *********************************************************/
-
- // Define the 4 local 3-D control points as arrays
- define n1x [0, 0, 1.6, 3.6, 0.4]
- define n1y [0, 0, 2.8, 0, -3.2]
- define n1z [0, 0, 0, 0, 0]
-
- define n2x [0, 1.6, 3.6, 0.4, -3.2]
- define n2y [0, 2.8, 0, -3.2, -0.4]
- define n2z [0, 0, 0, 0, 0]
-
- define n3x [1.6, 3.6, 0.4, -3.2, -0.4]
- define n3y [2.8, 0, -3.2, -0.4, 0]
- define n3z [0, 0, 0, 0, 0]
-
- define n4x [3.6, 0.4, -3.2, 0, 0]
- define n4y [0, -3.2, -0.4, 0, 0]
- define n4z [0, 0, 0, 0, 0]
-
- // Set up the key frames in another array
- define KF [0, 9, 19, 29, 39, 49]
-
- // Assign the value of "frame" to variable "F"
- define F frame
-
- // Determine what key frame sequence we're in
- if (F <= KF[1]) // <= 9
- define key 0
- if (F > KF[1] && F <= KF[2]) // > 9 && <= 19
- define key 1
- if (F > KF[2] && F <= KF[3]) // > 19 && <= 29
- define key 2
- if (F > KF[3] && F <= KF[4]) // > 29 && <= 39
- define key 3
- if (F > KF[4]) // > 39
- define key 4
-
- // Calculate the value of "t" from the
- // current frame and key frame sequence
- define F1 KF[key]
- define F2 KF[key + 1]
- define t (F - F1) / (F2 - F1)
-
- /****************************************************************
- Calculate the values of the object's location vector using the
- Catmull-Rom spline equation:
-
- P = t^3 * (-0.5 * P1) + t^3 * (1.5 * P2) + t^3 * (-1.5 * P3) +
- t^3 * (0.5 * P4) + t2 * P1 + t^2 * (-2.5 * P2) + t^2 *
- (2 * P3) + t^2 * (-0.5 * P4) + t * (-0.5 * P1) + t *
- (0.5 * P3) + P2
- ****************************************************************/
-
- define t2 t * t
- define t3 t2 * t
-
- define Px t3 * (-0.5 * n1x[key]) + t3 * (1.5 * n2x[key]) + t3 *
- (-1.5 * n3x[key]) + t3 * (0.5 * n4x[key]) + t2 *
- n1x[key] + t2 * (-2.5 * n2x[key]) + t2 * (2 * n3x[key]) +
- t2 * (-0.5 * n4x[key]) + t * (-0.5 * n1x[key]) + t *
- (0.5 * n3x[key]) + n2x[key]
-
- define Py t3 * (-0.5 * n1y[key]) + t3 * (1.5 * n2y[key]) + t3 *
- (-1.5 * n3y[key]) + t3 * (0.5 * n4y[key]) + t2 *
- n1y[key] + t2 * (-2.5 * n2y[key]) + t2 * (2 * n3y[key]) +
- t2 * (-0.5 * n4y[key]) + t * (-0.5 * n1y[key]) + t *
- (0.5 * n3y[key]) + n2y[key]
-
- define Pz t3 * (-0.5 * n1z[key]) + t3 * (1.5 * n2z[key]) + t3 *
- (-1.5 * n3z[key]) + t3 * (0.5 * n4z[key]) + t2 *
- n1z[key] + t2 * (-2.5 * n2z[key]) + t2 * (2 * n3z[key]) +
- t2 * (-0.5 * n4z[key]) + t * (-0.5 * n1z[key]) + t *
- (0.5 * n3z[key]) + n2z[key]
-
- // Now move the sphere to the new location
- object {
- sphere <0, 0, 0>, 0.5
- reflective_red
- translate <Px, Py, Pz>
- }
-
- // Set the sky color and add a little haze
- background Grey
- haze 0.98, 25, Grey
-
- // Lights
- light <-5, 30, -100>
- light <5, 30, -100>
-
- // The floor...
- object {
- disc <0, 0, 0>, <0, 1, 0>, 10000
- texture {
- checker steely_blue,
- texture { shiny { color white }}
- }
- rotate <0, 25, 0>
- translate <0, -4.5, 0>
- }
-